package core.genetic.crossover;

import utility.*;
import core.*;
import core.genetic.*;
import core.neural.*;

public class LearningCrossover implements Crossover {

	
	private final int learningCasesCount;
	private final double learningKoef;
	
	public LearningCrossover(int learningCasesCount, double learningKoef) {
		this.learningCasesCount =learningCasesCount;
		this.learningKoef = learningKoef;
	}
	
	
	@Override
	public Individual crossover(Individual ind1, Individual ind2) {
		int length = ind1.getLength();
		Individual ind = new Individual(length);
		for (int i=0; i<length; i++)
			ind.setGene(i, ind1.getGene(i));
		
		//Individual ind = new Individual(ind1.getGenes().clone());
		
//		double[] in = new double[Mode.mode.brain.INPUTS];
//		for(int i = 0;i<learningCasesCount;i++) {
//			for(int j = 0;j<in.length;j++)
//				in[j] = 2*Utils.random.nextDouble()-1;
//			
//			double[] teach = Mode.mode.brain.calculateOutputs(ind2, in);
//
//			Mode.mode.brain.teach(ind, in, teach, learningKoef);					
//		}					
		
		Mode.mode.brain.learn(ind, ind2, learningKoef, learningCasesCount);
		
		return ind;
	}
	
}
